<script setup lang="ts">
import homeApi from '@/service/api/home'
import type { TabListItem } from '@/types/page/tab'
type PropsState = {
  visible: boolean
}

const emit = defineEmits(['change'])
withDefaults(defineProps<PropsState>(), {
  visible: false
})
const institutionList = ref<TabListItem[]>([])
const getInstitution = async () => {
  const { data } = await homeApi.institution()
  institutionList.value = [
    {
      id: 0,
      name: '全部'
    },
    ...data
  ]
}
getInstitution()

const handTab = (e: TabListItem) => {
  emit('change', toRaw(e))
}
</script>

<template>
  <n-collapse-transition :show="!visible">
    <div class="norem-stick-clasiify stick-clasiify">
      <div class="tabs">
        <div class="tab">
          <i class="esayIcon esayIcon-fengche"></i>
          <span>动态</span>
        </div>
        <div class="tab">
          <i class="esayIcon esayIcon-remen"></i>
          <span>热门</span>
        </div>
      </div>
      <div class="btns">
        <div
          class="btn"
          v-for="item in institutionList"
          :key="item.id"
          @click="handTab(item)"
        >
          {{ item.name }}
        </div>
      </div>
    </div>
  </n-collapse-transition>
</template>

<style scoped lang="scss">
.norem-stick-clasiify {
  position: fixed;
  top: 50px;
  width: 100%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: flex-start;
  overflow: hidden;
  transition: height 0.15s;
  background-color: #fff;
  z-index: 8;
}
.stick-clasiify {
  height: 60px;
  padding: 10px 30px;
  &:hover {
    height: 110px;
  }
}
.tabs {
  display: flex;
  align-items: center;
  font-size: 14px;
  gap: 0 20px;
  padding-top: 4px;
  .tab {
    cursor: pointer;
    color: #333;
    i {
      font-size: 14px;
    }
    span {
      margin-left: 3px;
      font-size: 13px;
    }
    &:hover {
      color: var(--n-color);
    }
  }
}
.btns {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  margin-left: 24px;
  gap: 10px 15px;
  .btn {
    letter-spacing: 2px;
    font-size: 11px;
    width: 100px;
    height: 30px;
    line-height: 30px;
    border: 1px solid #f1f2f3;
    border-radius: 6px;
    background-color: #f6f7f8;
    text-align: center;
    font-weight: 400;
    transition: background-color 0.3s, color 0.3s;
    cursor: pointer;
    color: #61666d;
    &:hover {
      background-color: #e3e5e7;
      color: #18191c;
    }
  }
}

@media (max-width: 800px) {
  .stick-clasiify {
    overflow-x: auto;
    top: 40px;
    height: 50px;
    padding: 10px;
    &:hover {
      height: 50px;
    }
    .tabs {
      display: none;
      padding: 0;
      margin: 0;
    }
    .tab {
      width: 50px;
    }
    .btns {
      margin-left: 0;
      flex-wrap: initial;
    }
  }
}
</style>
